using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using TrafficTrouble.Core;
using Microsoft.Xna.Framework;

namespace TrafficTrouble
{
    public class LevelFileStream : IDisposable
    {
        public Stream FileStream { get; private set; }
        public byte FormatVersion { get; private set; }

        public LevelFileStream(Stream stream, byte formatVersion)
        {
            this.FileStream = stream;
            this.FormatVersion = formatVersion;
        }

        public static LevelFileStream GetLevelStream(Grid level)
        {
            return GetLevelStream(level.Difficulty, level.Number);
        }
        public static LevelFileStream GetLevelStream(LevelDifficulty difficulty, int number)
        {
            return GetLevelStream(difficulty + "/" + difficulty + number);
        }
        public static LevelFileStream GetLevelStream(string levelFileName)
        {
            Stream stream = TitleContainer.OpenStream("Levels/" + levelFileName + ".ttl");

            byte version = (byte)stream.ReadByte();

            return new LevelFileStream(stream, version);
        }

        public void Dispose()
        {
            this.FileStream.Dispose();
        }
    }
}
